<?php
declare (strict_types = 1);

namespace app\model;

use think\helper\Arr;
use think\Model;

/**
 * @property integer $quantity
 * @property string $price
 * @property string $title
 * @property string $image
 * @property string $variant_title
 * @property string $variant_id
 * @property integer $order_id
 * @property string $sku
 * @property integer $is_repurchase 是否复购
 * @property string $original_price 原价
 */
class LineItems extends BaseModel
{
    public $autoWriteTimestamp = false;
    protected $field = [
        'order_id','price','product_id',
        'quantity','sku','title',
        'total_discount','variant_id','variant_title',
        'url','properties','options_with_values',
        'image','is_repurchase','original_price',
    ];
    protected $json = ['title','variant_title','properties','options_with_values'];
    protected $jsonAssoc = true;

    public function orders()
    {
        return $this->belongsTo(Orders::class,'order_id');
    }

    public function getTitleAttr($title)
    {
       return Arr::get($title,'title',$title);
    }

    public function getVariantTitleAttr($variant_title)
    {
        return Arr::get($variant_title,'title',$variant_title);
    }

}
